package com.yxlgateway.gateway.controller;

import com.yxlcommon.common.pojo.Category;
import com.yxlcommon.common.pojo.RespBean;
import com.yxlgateway.service.CategoryService;
import com.yxlcommon.common.vo.CategoryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: yxl
 * @since: 2021-11-22
 **/
@Slf4j
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    //所有分类
    @GetMapping("/categoryList")
    public RespBean listCategory(){
        return categoryService.listCategories();
    }

    //一级分类新作
    @GetMapping("/categoryNewList")
    public RespBean listCategoryNewList(){
        return categoryService.listNewFistLevelCategories();
    }

    //一级分类热门
    @GetMapping("/categoryHotList")
    public RespBean listCategoryHotList(){
        return categoryService.listHotFirstLevelCategories();
    }

    //二级分类
    @GetMapping("/listSecondLevelCategories")
    public RespBean listSecondLevelCategories(){
        return categoryService.listSecondCategories();
    }

    @GetMapping("/getAllCategory")
    public RespBean getAllCategory(@RequestParam(defaultValue = "1") Integer currentPage,
                                   @RequestParam(defaultValue = "10") Integer size,
                                   Category category){
        return categoryService.getAllCategory(currentPage, size, category);
    }

    @PostMapping("/addCategory")
    public RespBean<Integer> addCategory(@RequestBody CategoryVo category){
        return categoryService.addCategory(category);
    }

    @PostMapping("/editCategory")
    public RespBean<Integer> editCategory(@RequestBody Category category){
        return categoryService.editCategoryName(category);
    }

    @PostMapping("/getCategoryById")
    public RespBean<Category> getCategoryById(@RequestBody Category category){
        return categoryService.selectCategoryById(category);
    }

    @PostMapping("/deleteCategoryById")
    public RespBean<Integer> deleteCategoryById(@RequestBody Category category){
        return categoryService.deleteCategoryById(category);
    }
}
